package com.vancouver.knows.business.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.pangu.util.StringUtil;
import com.vancouver.knows.business.bean.BannerInfo;
import com.vancouver.knows.business.bean.BusinessInfo;
import com.vancouver.knows.business.bean.CommentInfo;
import com.vancouver.knows.business.bean.PostDetailInfo;
import com.vancouver.knows.business.bean.RelatedPostInfo;
import com.vancouver.knows.business.bean.UserPostDetailInfo;

/**
 * Created by Chris Li on 2016-07-15.
 */
public class FetchUserPostDetailInfoHandler extends ACheckableJsonParser {

    private UserPostDetailInfo userPostDetailInfo;

    @Override
    protected void parserContent(JSONObject content) throws Exception {
        userPostDetailInfo = new UserPostDetailInfo();

        String postDetails = content.getString("post_details");
        if (!StringUtil.isEmptyString(postDetails)) {
            userPostDetailInfo.setPostDetails(JSON.parseObject(postDetails, PostDetailInfo.class));
        }

        String hotComments = content.getString("hot_comments");
        if (!StringUtil.isEmptyString(hotComments)) {
            userPostDetailInfo.setCommentInfoList(JSON.parseArray(hotComments, CommentInfo.class));
        }

        String relatedPosts = content.getString("related_posts");
        if (!StringUtil.isEmptyString(relatedPosts)) {
            userPostDetailInfo.setRelatedPostInfoList(JSON.parseArray(relatedPosts, RelatedPostInfo.class));
        }

        String adBanner = content.getString("ad_banner");
        if (!StringUtil.isEmptyString(adBanner)) {
            userPostDetailInfo.setAdBanner(JSON.parseObject(adBanner, BannerInfo.class));
        }

        String suggestedBusiness = content.getString("suggested_business");
        if (!StringUtil.isEmptyString(suggestedBusiness)) {
            userPostDetailInfo.setBusinessInfoList(JSON.parseArray(suggestedBusiness, BusinessInfo.class));
        }
    }

    public UserPostDetailInfo getUserPostDetailInfo() {
        return userPostDetailInfo;
    }
}
